Overview
Thefetch_corporate_actions.py script retrieves corporate action events in two time scenarios: historical events (past 2 years) and upcoming events (next 2 months). This dual-fetch approach enables both historical analysis and future event tracking.
Purpose
Fetches corporate action data including:- Dividends - Cash dividend announcements
- Bonuses - Bonus share issues
- Stock Splits - Share split events
- Rights Issues - Rights offering announcements
- Quarterly Results - Result announcement dates
- Buybacks - Share buyback programs
API Endpoint
https://ow-scanx-analytics.dhan.co/customscan/fetchdtPOSTRequest Payload
Parameters
Field to sort by (Ex-Date)
Sort order (
asc for chronological, desc for reverse)Maximum number of records to fetch
Fields to retrieve:
CorpAct.ActType- Action type (DIVIDEND, BONUS, etc.)Sym- Stock symbolDispSym- Display nameCorpAct.ExDate- Ex-dateCorpAct.RecDate- Record dateCorpAct.Note- Details (e.g., “Rs 10 per share”)
Filter parameters:
{"field": "Seg", "op": "", "val": "E"}- Equity segment{"field": "OgInst", "op": "", "val": "ES"}- Equity stocks{"field": "CorpAct.ExDate", "op": "lte", "val": "<END_DATE>"}- Date range (end){"field": "CorpAct.ExDate", "op": "gte", "val": "<START_DATE>"}- Date range (start){"field": "Mcapclass", "op": "", "val": "Largecap,Midcap,Smallcap,Microcap"}- All cap sizes{"field": "CorpAct.ActType", "op": "", "val": "BONUS,DIVIDEND,QUARTERLY RESULT ANNOUNCEMENT,SPLIT,RIGHTS,BUYBACK"}- Action types
Output Files
Historical corporate actions from past 2 years. Each object contains:Sorted by ExDate (ascending).
Upcoming corporate actions for next 2 months. Same structure as historical data.
Function Signature
Dependencies
requests- HTTP clientjson- JSON processingdatetime,timedelta- Date calculations (IST timezone)os- File operations
pipeline_utils.get_headers()- Returns API headers with Origin header
None - Fetches data directly from API
Code Example
Usage
Performance
- Execution Time: ~5-10 seconds
- API Calls: 2 requests (one for historical, one for upcoming)
- Output Size: Variable (depends on number of events)
- Concurrency: Sequential (no threading)
Date Ranges
Historical Scenario
- Start: 2 years before today (IST)
- End: Yesterday (IST)
- Purpose: Analyze past corporate actions and their market impact
Upcoming Scenario
- Start: Today (IST)
- End: 2 months ahead (IST)
- Purpose: Track upcoming events for event-driven trading strategies
Data Flattening
The API returns nested structures withCorpAct arrays:
Notes
- Uses IST timezone (UTC +5:30) for all date calculations
- Strict date filtering ensures no leakage between historical and upcoming datasets
- Filters by market cap classes (Largecap, Midcap, Smallcap, Microcap)
- Action types: BONUS, DIVIDEND, QUARTERLY RESULT ANNOUNCEMENT, SPLIT, RIGHTS, BUYBACK
- Results are sorted chronologically by Ex-Date